'''
Created on 10.05.2011

@author: marion
'''
import numpy as np
import matplotlib.pyplot as plt
import os

colors = {
"ST": "green",
"SL": "red",
"OP": "black",
}
 
point_colors = {}

class Point(object):
    def __init__(self, id, x, y, z):
        self.id = id
        self.x = x
        self.y = y
        self.z = z
 
        @property
        def color(self):
            return colors[point_colors[self.id]]
        def __repr__(self):
            return "Point(%d, %f, %f, %f)" % (self.id, self.x, self.y, self.z)

def read_files():
    the_points = []
    for line in open("../../data/ExpPos-Part8.txt"):
        try:
            L = line.strip().split()
            if len(L) != 4:
                continue
            id, x, y, z = int(L[0]), float(L[1]), float(L[2]), float(L[3])
            point = Point(id, x, y, z)
            the_points.append(point)
        except:
            pass
    return the_points


# the random data
x = []
y = []
z = []

the_points = read_files()

for point in the_points:
    
    x.append(point.x/10000)
    y.append(point.y/10000)
    z.append(point.z/10000)


fig = plt.figure(1, figsize=(10.0,10.0))

from mpl_toolkits.axes_grid1 import make_axes_locatable


props = dict(alpha=0.1, edgecolors='none' )

# the scatter plot:
axScatter = plt.subplot(111)
axScatter.scatter(x, y, s = 30, **props)
axScatter.set_aspect(1.)

# create new axes on the right and on the top of the current axes
# The first argument of the new_vertical(new_horizontal) method is
# the height (width) of the axes to be created in inches.
divider = make_axes_locatable(axScatter)
axHistx = divider.append_axes("top", 1.2, pad=0.1, sharex=axScatter)
axHisty = divider.append_axes("right", 1.2, pad=0.1, sharey=axScatter)

# make some labels invisible
plt.setp(axHistx.get_xticklabels() + axHisty.get_yticklabels(),
         visible=False)

# now determine nice limits by hand:
binwidth = 0.8
xymax = np.max( [np.max(np.fabs(x)), np.max(np.fabs(y))] )
lim = ( int(xymax/binwidth) + 1) * binwidth

bins = np.arange(0, lim + binwidth, binwidth)
axHistx.hist(x, bins=bins)
axHisty.hist(y, bins=bins, orientation='horizontal')

# the xaxis of axHistx and yaxis of axHisty are shared with axScatter,
# thus there is no need to manually adjust the xlim and ylim of these
# axis.

#axHistx.axis["bottom"].major_ticklabels.set_visible(False)
for tl in axHistx.get_xticklabels():
    tl.set_visible(False)
axHistx.set_yticks([0, 50, 100])

#axHisty.axis["left"].major_ticklabels.set_visible(False)
for tl in axHisty.get_yticklabels():
    tl.set_visible(False)
axHisty.set_xticks([0, 50, 100])

plt.draw()
plt.show()